/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package idea.sfo.viewer.designer;


import idea.sfo.viewer.Canvas;
import idea.sfo.viewer.graphics.Drawable;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;


/**
 *
 * @author renke002
 */
public abstract class DesignerGraphic implements Drawable
{

    /**
     *
     */
    protected Rectangle container;
    /**
     * Background Color.
     */
    private Color bgColor;
    /**
     * Border Color.
     */
    private Color borderColor;
    /**
     * If true, the border will be visible.
     */
    private boolean borderVisible;
    /**
     * Foreground/Text Color.
     */
    private Color fgColor;
    /**
     * If true, this element is selected (highlighted) and will be colored/drawn
     * differently.
     */
    private boolean isSelected;


    /**
     *
     * @param rowNum
     * @param colNum
     * @param myWidth
     * @param myHeight
     * @param prevColWidths
     * @param prevHeights
     * @param label
     */
    public DesignerGraphic( Integer rowNum , Integer colNum , Long myWidth , Long myHeight , Long prevColWidths , Long prevRowHeights )
    {
        this.container = new Rectangle(
                (int) ( prevColWidths / Canvas.FU_SCALE_FACTOR ) ,
                (int) ( prevRowHeights / Canvas.FU_SCALE_FACTOR ) ,
                (int) ( myWidth / Canvas.FU_SCALE_FACTOR ) ,
                (int) ( myHeight / Canvas.FU_SCALE_FACTOR ) );

        this.bgColor = Color.LIGHT_GRAY;
        this.fgColor = Color.BLACK;
    }


    /**
     *
     * @param g2d
     */
    @Override
    public void draw( Graphics2D g2d )
    {
        if ( this.isSelected )
        {
            g2d.setColor( Color.ORANGE );
            g2d.draw(
                    new Rectangle( this.container.x + 1 , this.container.y + 1 ,
                    this.container.width - 2 , this.container.height - 2 ) );
        }
        else
        {
            if ( this.borderVisible )
            {
                // draw the border
                g2d.setColor( this.fgColor );
            }
            else
            {
                // do NOT draw the object's border
                g2d.setColor( this.bgColor );
            }
        }
        // need to change to only draw the visible borders.
        g2d.draw( container );
    }


//    /**
//     *
//     * @param x
//     * @param y
//     */
//    @Override
//    public void moveTo( int x , int y )
//    {
//        this.container.x = x;
//        this.container.y = y;
//    }


    /**
     * Set this element's border to be visible.
     * <p/>
     * @param visible
     */
    public void setBorderVisible( boolean visible )
    {
        this.borderVisible = visible;
    }


    /**
     * Set this element as selected, which means it will be colored/drawn
     * differently from the others.
     * <p/>
     * @param selected
     */
    public void setSelected( boolean selected )
    {
        this.isSelected = selected;
    }

}
